//command.cpp
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <fstream>

using namespace std;

#ifdef __WIN32__
#define cl "cls"
#else
#define cl "clear"
#endif

std::string USERname = "Administrator";
std::string password = "";
bool is_login_now;
std::string PCname = "VM-PC";
std::string workfolder = "this-PC";
ifstream file_tree;
void login()
{
	do{
		system(cl);
		printf("user:[%s]\n",USERname.c_str());
		printf("password:");
		string pw;
		getline(cin,pw,'\n');
		if(pw == password)
		{
			is_login_now = true;
			system(cl);
    		printf("user[%s] login of %s\n",USERname.c_str(),PCname.c_str());
			return ;
		}
	}while(true);
}

void Error(int id)
{
	if(id == 404)
	{
		cout << "Error: No this Command !\n";
	}
}

int main()
{
    system(cl);
    printf("Loading...");
    system("mkdir this-PC");
    ifstream is_open;
    is_open.open("register.dir",std::ios::in);
    if(!is_open)
    {
        is_open.close();
        ofstream new_dir;
        new_dir.open("register.dir",std::ios::out);
        new_dir << "\\ sys tmp\n";
        new_dir.close();
    }
    else{
        is_open.close();
    }
    file_tree.open("register.dir",std::ios::in);
    login();
    system(cl);
    printf("user[%s] login of %s\n",USERname.c_str(),PCname.c_str());
    while(true)
    {
        printf("[%s|%s]> ",PCname.c_str(),USERname.c_str());
        std::string command;
        cin >> command;
        if(command == "set")
        {
            //set?眉谩?
            std::string setof;
            cin >> setof;
            if(setof == "password")
            {
            	string new_password;
				cin >> new_password;
				password = new_password;
				is_login_now = false;
				login();
				cout << "Press space key to continue . . .";
			}
			else{
				Error(404);
			}
        }
        else if(command == "exit")
        {
            //exit?眉谩?
            signed int exit_val;
            cin >> exit_val;
            return exit_val;
        }
        else if(command == "help")
        {
			cout << "set password [new password]\n";
			cout << "exit [val]\nhelp\necho [str]\nnotepad\nclear\n";
		}
        else if(command == "echo")
        {
			string str;
			cin >> str;
			cout << str << "\n";
		}
        else if(command == "notepad")
        {
			string tmpstr;
			while(cin >> tmpstr);
    	}
        else if(command == "clear")
        {
			system(cl);
		}
        else if(command == "mkdir")
        {
			string dirname;
            cin >> dirname;
            string cmd = "mkdir ./";
            string C_cd;
            C_cd = "cd ";
            C_cd += workfolder;
            system(C_cd.c_str());
            cmd += dirname;
            system(cmd.c_str());
		}
        else if(command == "")
        {
			
		}
        else if(command == "")
        {
			
		}
        else if(command == "")
        {
			
		}
        else if(command == "")
        {
			
		}
        else if(command == "")
        {
			
		}
        else if(command == "")
        {
			
		}
		else
		{
			Error(404);
		}
		cin.ignore(numeric_limits<streamsize>::max(), '\n');
    }
}
